﻿using System.Data.Entity;

using NeGroid.ChampionshipManager.Core;
using NeGroid.ChampionshipManager.Persistance.Mappings;
using NeGroid.ChampionshipManager.Persistance.Migrations;

namespace NeGroid.ChampionshipManager.Persistance
{
	public class ChampionshipManagerDb : DbContext
	{
		public ChampionshipManagerDb()
		{
			Database.SetInitializer(new MigrateDatabaseToLatestVersion<ChampionshipManagerDb, Configuration>());
		}
		public DbSet<Player> Players { get; set; }
		public DbSet<Team> Teams { get; set; }
		public DbSet<Game> Games { get; set; }
		public DbSet<GameInfo> GameInfos { get; set; }
		public DbSet<Goal> Goals { get; set; }
		public DbSet<Refery> Referies { get; set; }
		public DbSet<PlayerTransfer> Transfers { get; set; }
		public DbSet<Substition> Substitions { get; set; }

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			modelBuilder.Configurations.Add(new PlayerMap());
			modelBuilder.Configurations.Add(new TeamMap());
			modelBuilder.Configurations.Add(new GameMap());
			modelBuilder.Configurations.Add(new GameInfoMap());
			modelBuilder.Configurations.Add(new GoalMap());
			modelBuilder.Configurations.Add(new ReferyMap());
			modelBuilder.Configurations.Add(new PlayerTransferMap());
			modelBuilder.Configurations.Add(new SubstitionMap());
		}
	}
}
